﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Collections;

namespace SellerProject.testfolder
{
    public class User
    {
        #region "Fields and Properties"
        private int userId;
        private string userName;
        private string password;

        public int UserId
        {
            get { return userId; }
            set { userId = value; }
        }
        public string UserName
        {
            get { return userName; }
            set { userName = value; }
        }
        public string Password
        {
            get { return password; }
            set { password = value; }
        }
        private Role role;
        public Role Role{get { return role; }set { role = value; }}
        private RoleCollection roles;
        public RoleCollection Roles{get{if (roles == null){roles = new RoleCollection();}return roles;}}
        #endregion

        #region "Constructors"
        public User() { }
        public User(int id, string name, string password)
        {
            this.UserId = id;
            this.UserName = name;
            this.Password = password;
        }
        #endregion

        #region "Methods"
        #endregion
    }

    public class UserCollection : CollectionBase
    {
        public User this[int index]
        {
            get { return (User)List[index]; }
            set { List[index] = value; }
        }
        public int Add(User value)
        {
            return (List.Add(value));
        }
        public int IndexOf(User value)
        {
            return (List.IndexOf(value));
        }
        public void Insert(int index, User value)
        {
            List.Insert(index, value);
        }
        public void Remove(User value)
        {
            List.Remove(value);
        }
        public bool Contains(User value)
        {
            return (List.Contains(value));
        }

        public User FindUserById(int userId)
        {
            foreach (User user in List)
            {
                if (user.UserId == userId)
                {
                    return user;
                }
            }
            return null;
        }
        public UserCollection FindMatchingUsers(string search)
        {
            if (search == null)
            {
                throw new ArgumentNullException("search cannot be null");
            }
            UserCollection matchingUsers = new UserCollection();
            foreach (User user in List)
            {
                string userName = user.UserName;
                if (userName != null && userName.StartsWith(search))
                {
                    matchingUsers.Add(user);
                }
            }
            return matchingUsers;
        }
    }
}